<?php
require_once('config.inc.php');

page_open(array('sess'=>'MySession', 'auth'=>'MyAuth', 'perm'=>'MyPerm'));
page_close();

/**
 * get_row_user
 */ 
function get_row_user($uid, $login, $perms, $permsval, $name)
{
  return <<<EORU
  <tr id="row_user_$uid">
    <td>$login</td>
    <td>$name</td>
    <td>$perms</td></tr>

<script type="text/javascript">
  window.Admin.look_user("$uid", "$login", "$name", [$permsval]);
</script>
EORU;
}

/**
 * get_all_perms_code
 */
function get_all_perms_code($perms)
{
  return <<<EOAPC
<script type="text/javascript">
  window.Admin.set_perms("$perms");
</script>
EOAPC;
}

// ACTIONS
switch (rd_get('action'))
{
case 'get_users':
  $users = Gestion::get_users();
  foreach ($users as $user)
  {
    $permsval = array();
    foreach (explode(',', $user['perms']) as $p)
    {
      array_push($permsval, $perm->permissions[$p]);
    }
    print get_row_user( $user['uid']
                      , $user['login']
                      , $user['perms']
                      , implode(',', $permsval)
                      , $user['name']
                      );
  }
  print get_all_perms_code(implode(',', array_keys($perm->permissions)));
  break;
}
?>
